home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15320 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Check if a file exists?
  5. Date: Thu, 18 Apr 96 12:59:33 GMT
  6. Organization: none
  7. Message-ID: <829832373snz@genesis.demon.co.uk>
  8. References: <4kp7pg$upe@news-s01.ny.us.ibm.net> <317261E6.31D0@spectratek.co.uk> <829569968snz@genesis.demon.co.uk> <3172B2E8.7D70@willows.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <3172B2E8.7D70@willows.com>
  15.            tarang@willows.com "Tarang Deshpande" writes:
  16.  
  17. >Lawrence Kirby wrote:
  18. >> 
  19. >> In article <317261E6.31D0@spectratek.co.uk>
  20. >>            dean_darlison@spectratek.co.uk "Dean Darlison" writes:
  21. >> 
  22. >> >man access
  23. >> 
  24. >> If that works on your system then the contents should tell you that this
  25. >> function is inappropriate for the question asked.
  26.  
  27. >Under SUNOS 5.4, LINUX 1.1.46 and conforming to SVID, AT&T, POSIX, 
  28. >X/OPEN, and BSD 4.3
  29. >
  30. >#include <unistd.h>
  31. >int access (const char *path, int amode)
  32. >
  33. >where amode is F_OK then the function is used to test for existance.
  34.  
  35. Your man page should also have told you that access tests for accessibility
  36. (rather than existence) of the file against real UID and GID instead of the
  37. usual effective UID and GID which makes it inappropriate for almost all uses.
  38. Donald Lewine says it well (POSIX Programmer's Guide):
  39.  
  40. "access() uses the real UID, not the effective UID. It is not a general
  41.  utility for finding out "Can I do this?" before doing a call. It is used by
  42.  SETUID programs to check their actions"
  43.  
  44. As I said previously, use stat().
  45.  
  46. For non-Unix/POSIX systems that implement an access() call it is worth
  47. knowing that your usage of access() may not be as portable as you think.
  48.  
  49. Apologies for the off-topic posts but I hate to see bad advice left
  50. unchallenged.
  51.  
  52. -- 
  53. -----------------------------------------
  54. Lawrence Kirby | fred@genesis.demon.co.uk
  55. Wilts, England | 70734.126@compuserve.com
  56. -----------------------------------------
  57.